package scau.redi.social_platform.common.util;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 响应对象
 */
public class ResponseUtil {

    /**
     * 响应数据
     */
    private Object data;

    /**
     * 响应信息
     */
    private String message;

    /**
     * 响应代码
     * 大于0：响应失败。具体失败代码请查看 ResponseCode 类
     * 0：响应成功
     */
    private int code;

    /**
     * session
     */
    private HttpSession session;

    public HttpSession getSession() {
        return session;
    }

    public void setSession(HttpSession session) {
        this.session = session;
    }

    public static Map<String, Object> success() {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("message", "操作执行成功");
        return map;
    }

    public static Map<String, Object> success(String message) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("message", message);
        return map;
    }

    public static Map<String, Object> success(String message, int code) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", code);
        map.put("message", message);
        return map;
    }

    public static Map<String, Object> success(Object data) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("message", "操作成功");
        map.put("data", data);
        return map;
    }

    public static Map<String, Object> success(String message, int code, Object data) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", code);
        map.put("message", message);
        map.put("data", data);
        return map;
    }

    public static Map<String, Object> fail() {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 1);
        map.put("message", "操作失败！");
        return map;
    }

    public static Map<String, Object> fail(String message) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 1);
        map.put("message", message);
        return map;
    }

    public static Map<String, Object> fail(String message, Object data) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 1);
        map.put("message", message);
        map.put("data", data);
        return map;
    }

    public static Object fail(int errno, String errmsg) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", errno);
        obj.put("errmsg", errmsg);
        return obj;
    }


}
